#include "StdAfx.h"
#include "Line.h"
#include "LinkedNode.h"
#include "EndPoint.h"
#include <cassert>

CEndPoint::CEndPoint()
{
	m_pLinkedNode	 = NULL;
	m_pArrowBelongTo = NULL;
}

CEndPoint::CEndPoint(const CPoint& p_point, CLinkedNode* p_pLinkedNode, CLine* p_pArrow)
{
	m_position		 = p_point;
	m_pLinkedNode	 = p_pLinkedNode;
	m_pArrowBelongTo = p_pArrow;
}

void CEndPoint::moveDelta( const CPoint& p_point )
{
	m_position += p_point;
	m_pArrowBelongTo->calTurningPointList();
}

void CEndPoint::updateWithLinkedNode()
{
	if( m_pLinkedNode )
		m_position = m_pLinkedNode->getPosition();
	m_pArrowBelongTo->calTurningPointList();
}

void CEndPoint::attach( CLinkedNode* p_pLinkedNode )
{
	if( p_pLinkedNode )
	{
		m_pLinkedNode = p_pLinkedNode;
		p_pLinkedNode->getEndPointList().push_back(this);
	}
}

void CEndPoint::detach()
{
	if( m_pLinkedNode )
	{
		m_pLinkedNode->getEndPointList().remove(this);
		m_pLinkedNode = NULL;
	}
}